﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Media;
using Color=System.Windows.Media.Color;

namespace SmartBoard.Background.Dialogs
{
    public partial class ChangeBackgroundDialog : Form, IChangeBackgroundDialog
    {
        public ChangeBackgroundDialog()
        {
            InitializeComponent();
        }

        #region Implementation of IChangeBackgroundDialog

        public DialogResult ShowModal()
        {
            return this.ShowDialog();
        }

        private Color _color;
        private int r;
        private int g;
        private int b;

        public Color SelectedColor
        {
            get
            {
                return Color.FromRgb((byte) r, (byte) g, (byte) b);
            }
            set
            {
                r = value.R;
                g = value.G;
                b = value.B;
                w_txtR.Text = value.R.ToString();
                w_txtG.Text = value.G.ToString();
                w_txtB.Text = value.B.ToString();
            }
        }

        #endregion

        private void HandleRChanged(object sender, EventArgs e)
        {
            int.TryParse(this.w_txtR.Text, out r);
            if(r<0) r = 0;
            if(r>255) r = 255;
            w_lblColor.BackColor =System.Drawing.Color.FromArgb(255, r, g, b);
        }

        private void HandleGChanged(object sender, EventArgs e)
        {
            int.TryParse(this.w_txtG.Text, out g);
            if (g < 0) g = 0;
            if (g > 255) g = 255;
            w_lblColor.BackColor = System.Drawing.Color.FromArgb(255, r, g, b);
        }

        private void HandleBChanged(object sender, EventArgs e)
        {
            int.TryParse(this.w_txtB.Text, out b);
            if (b < 0) b = 0;
            if (b > 255) b = 255;
            w_lblColor.BackColor = System.Drawing.Color.FromArgb(255, r, g, b);
        }
    }
}
